#include <stdio.h>
#include <string.h>
typedef struct{
    char name[25];
    int score;
}student;
int cmp(student x,student y){
    if(x.score!=y.score)return x.score<y.score;
    return (strcmp(x.name,y.name)>0)?1:0;
}
int main(){
    int n;
    scanf("%d",&n);
    //getchar();
    student stu[105];
    for(int i=0;i<n;i++){
        scanf("%s %d",stu[i].name,&stu[i].score);
    }
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            if(cmp(stu[i],stu[j])){
                student tmp;
                tmp = stu[j];
                stu[j] = stu[i];
                stu[i] = tmp;
            }
        }
    }
    for(int i=0;i<n;i++){
        printf("Name:%s\ntotal:%d\n\n",stu[i].name,stu[i].score);
    }
    return 0;
}